package com.neo.subscribe.schedule;

import com.google.common.base.Stopwatch;
import com.neo.subscribe.stamp.service.StampService;
import com.neo.subscribe.wechat.service.StampMessageService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.concurrent.TimeUnit;

@Slf4j
@Configuration
@EnableScheduling
@AllArgsConstructor
public class StampScheduleTask {

    private final StampMessageService stampMessageService;

    private final StampService stampService;


    //@Scheduled(cron = "0 0/1 * * * ?") // 每一分钟执行
    @Scheduled(cron = "0 0 8,20 * * ?") // 早晚八点执行
    private void sendStampMessage() {
        Stopwatch stopwatch = Stopwatch.createStarted();
        log.info("执行【群发邮票消息】定时任务 =========> 开始");
        stampMessageService.sendStampMessage();
        log.info("执行【群发邮票消息】定时任务 =========> 结束，耗时：{}/s", stopwatch.elapsed(TimeUnit.SECONDS));
    }

    //@Scheduled(cron = "0 0/1 * * * ?") // 每一分钟执行
    @Scheduled(cron = "0 0 7,19 * * ?") // 早晚七点执行
    private void spiderStampList() {
        Stopwatch stopwatch = Stopwatch.createStarted();
        log.info("执行【爬取邮票信息】定时任务 =========> 开始");
        stampService.spiderStampList();
        log.info("执行【爬取邮票信息】定时任务 =========> 结束，耗时：{}/s", stopwatch.elapsed(TimeUnit.SECONDS));
    }

}
